package com.fiberhome.app.network.socket;

import android.text.TextUtils;

import com.fiberhome.app.network.CacheBuilder;
import com.fiberhome.app.network.MD5Util;

/**
 * Created by Deed on 2018/1/29.
 */

abstract class SocketBuilder extends CacheBuilder {
    /**
     * TCP_PORT
     */
    final int port;
    /**
     *
     */
    final String ipAddress;

    /**
     * 超时
     */
    int timeOut = 10000;

    String sendData;
    private String string;

    SocketBuilder(int port, String ipAddress) {
        this.port = port;
        this.ipAddress = ipAddress;
    }

    @Override
    public String string() {
        if (TextUtils.isEmpty(string)) {
            StringBuilder sb = new StringBuilder(ipAddress);
            sb.append(port);
            if (!TextUtils.isEmpty(sendData)) {
                sb.append(sendData);
            }
            string = MD5Util.md5(sb.toString());
        }
        return string;
    }

    /**
     * set value
     *
     * @param timeOut value
     */
    public SocketBuilder timeOut(int timeOut) {
        this.timeOut = timeOut;
        return this;
    }

    /**
     * set value
     * @param sendData String
     * @return SocketBuilder
     */
    public SocketBuilder sendData(String sendData) {
        this.sendData = sendData;
        return this;
    }
}
